<template>
  <div>
    <div class="top">
      <div class="button">
        <span
          class="iconfont icon-zuoyoujiantou"
          @click="$router.push('/userinfo')"
        ></span>
        我的歌单
      </div>
    </div>

    <van-tabs v-model="active">
      <van-tab title="自建歌单">
        <div class="zijbox" ><!-- @click="$router.push('/ranklist')"-->
          <router-link class="box" tag="div" :to="'./rank/ranklist?id='+item.id" v-for="(item, index) in mylist1" :key="index">
            <img
              :style="'background-image: url(' + item.coverImgUrl + ')'"
              alt=""
            />
            <span class="name">{{ item.name }}</span>
            <span>共{{ item.trackCount }}首</span>
          </router-link>
        </div>
      </van-tab>
      <van-tab title="收藏歌单">
        <div class="zijbox">
          <router-link class="box" tag="div" :to="'./rank/ranklist?id='+item.id" v-for="(item, index) in mylist2" :key="index">
            <img
              :style="'background-image: url(' + item.coverImgUrl + ')'"
              alt=""
            />
            <span class="name">{{ item.name }}</span>
            <span>共{{ item.trackCount }}首</span>
          </router-link>
        </div>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
import { getUserPlaylist } from "../../api/login";
export default {
  data() {
    return {
      active: 2,
      mylist: null, //自建歌单
      mylist1: [],
      mylist2: [],
    };
  },
  methods: {
    getUserPlaylistFun() {
      this.userId = window.localStorage.getItem("uid");
      getUserPlaylist({ uid: this.userId }).then((data) => {
        console.log(data.playlist);
        this.mylist = data.playlist;
        for (let i = 0; i < this.mylist.length; i++) {
          if (i < 4) {
            this.mylist1.push(this.mylist[i]);
          } else {
            this.mylist2.push(this.mylist[i]);
          }
        }
      });
    },
  },
  created() {
    this.getUserPlaylistFun();
  },
};
</script>

<style lang="less">
.top {
  // width: 100%;
  height: 50px;
  position: relative;
  background-color: #d4473c;
  .button {
    font-size: 18px;
    position: absolute;
    left: 12px;
    top: 12px;
    color: #fff;
  }
}
.van-tab {
  font-size: 17px;
}
.zijbox {
  .box {
    // width: 100%;
    border: 1px solid gainsboro;
    box-shadow: 1px 1px 5px 0px #888888;
    border-radius: 10px;
    margin-top: 5px;
    overflow: hidden;
    position: relative;
    margin: 10px 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-wrap: normal;

    .name {
      width: 200px;
      position: absolute;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      margin-left: 120px;
      margin-top: -95px;
      word-wrap: normal;
    }
    span:last-child {
      position: absolute;
      // float: right;
      margin-left: 120px;
      margin-top: -70px;
    }
    img {
      width: 100px;
      height: 100px;
      border-radius: 10px;
      background-size: cover;
      margin: 10px 10px;
    }
  }
}
</style>